﻿using System;
using Sources;
using System.Collections.Generic;

namespace DeploySources
{
	/// <summary>
	/// Artefacts to deploy
	/// a good PlugIn for Notepad++ with intellisence can be found here
	/// Url: https://csscriptnpp.codeplex.com/releases/view/630716
	/// Note: Edit the file directly where the Sources.dll is located
	/// </summary>
	public class Artefacts
	{
		/// <summary>
		/// This Method is used to return all Fields to deploy
		/// </summary>
		/// <returns>All Fields to deploy</returns>
		public static List<FieldArtefact> GetFields()
		{
			var result = new List<FieldArtefact>
			{
				Fields.SampleTextField,
				Fields.SampleChoiceField,
				Fields.SampleBoolField,
				Fields.SampleDateTimeField,
				Fields.SampleLookupField,
				Fields.SampleLookupMultiField,
				Fields.SampleNoteField,
				Fields.SampleNumberField,
				Fields.SampleUrlField,
				Fields.SampleUserField,
				Fields.SampleUserMultiField
			};


			return result;
		}

		/// <summary>
		/// This Method is used to return all ContentTypes to deploy
		/// </summary>
		/// <returns>All ContentTypes to deploy</returns>
		public static List<ContentTypeArtefact> GetContentTypes()
		{
			var result = new List<ContentTypeArtefact>
			{
				ContentTypes.SampleContentType
			};


			return result;
		}

		/// <summary>
		/// This Method is used to return all Lists to deploy
		/// </summary>
		/// <returns>All Lists to deploy</returns>
		public static List<ListArtefact> GetLists()
		{
			var result = new List<ListArtefact>
			{
				Lists.LookAtList,
				Lists.SampleList
			};


			return result;
		}

		static readonly string _fieldsGroup = "Sample Fields";

		struct Fields
		{
			public static readonly FieldArtefact SampleTextField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleTextField",
				DisplayName = "Text Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.Text,
				Required = false
			};

			public static readonly FieldArtefact SampleBoolField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleBoolField",
				DisplayName = "Bool Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.Boolean,
				Required = false
			};

			public static readonly FieldArtefact SampleChoiceField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleChoiceField",
				DisplayName = "Choice Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.Choice,
				Required = false,
				Choices = new[] {"Choice 1", "Choice 2", "Choice 3"}
			};

			public static readonly FieldArtefact SampleDateTimeField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleDateTimeField",
				DisplayName = "Date Time Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.DateTime,
				Format = FieldFormatEnum.DateOnly,
				Required = false
			};
			
			public static readonly FieldArtefact SampleLookupField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleLookupField",
				DisplayName = "Lookup Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.Lookup,
				Required = false,
				FieldRef = "Title",
				ListName = "Look at list"
			};

			public static readonly FieldArtefact SampleLookupMultiField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleLookupMultiField",
				DisplayName = "Lookup Multi Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.LookupMulti,
				Required = false,
				FieldRef = "Title",
				ListName = "Look at list"
			};

			public static readonly FieldArtefact SampleNoteField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleNoteField",
				DisplayName = "Note Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.Note,
				RichText = true,
				RichTextMode = RichTextModeEnum.FullHtml,
				Required = false
			};

			public static readonly FieldArtefact SampleNumberField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleNumberField",
				DisplayName = "Number Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.Number,
				Required = false,
				Min = 0,
				Max = 100
			};

			public static readonly FieldArtefact SampleUrlField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleUrlField",
				DisplayName = "Url Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.URL,
				Required = false,
				Format = FieldFormatEnum.Hyperlink
			};

			public static readonly FieldArtefact SampleUserField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleUserField",
				DisplayName = "User Field",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.User,
				Required = false
			};

			public static readonly FieldArtefact SampleUserMultiField = new FieldArtefact
			{
				ID = Guid.NewGuid(),
				Name = "SampleUserMultiField",
				DisplayName = "User Field Multi",
				Group = _fieldsGroup,
				Type = FieldTypeEnum.UserMulti,
				Required = false
			};

		}

		struct ContentTypes
		{
			public static readonly ContentTypeArtefact SampleContentType = new ContentTypeArtefact
			{
				ID = "0x0100" + Guid.NewGuid().ToString("N"),
				Name = "Sample Contenttype",
				Description = "Sample Contenttype description",
				Group = "Sample Content Types",
				FieldItems = new[]
				{
					Fields.SampleTextField,
					Fields.SampleChoiceField,
					Fields.SampleBoolField,
					Fields.SampleDateTimeField,
					Fields.SampleLookupField,
					Fields.SampleLookupMultiField,
					Fields.SampleNoteField,
					Fields.SampleNumberField,
					Fields.SampleUrlField,
					Fields.SampleUserField,
					Fields.SampleUserMultiField
				}
			};
		}

		struct Lists
		{
			public static readonly ListArtefact SampleList = new ListArtefact
			{
				Title = "Sample List",
				RemoveOtherContentTypes = true,
				Description = "Sample list for all supported fieldtypes",
				ContentTypes = new[]
				{
					ContentTypes.SampleContentType
				}
			};

			public static readonly ListArtefact LookAtList = new ListArtefact
			{
				Title = "Look at list",
				Description = "List to look at for lookup fields"
			};
		}
	}
}
